package com.piece.core.oauth.config;

import org.springframework.core.Ordered;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.TokenGranter;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import java.util.ArrayList;
import java.util.List;

public interface AuthorizationServerProvider extends Ordered {

    /**
     * 自定义授权模式
     */
    default List<TokenGranter> addTokenGranter(AuthenticationManager authenticationManager,
                                               OAuth2RequestFactory requestFactory,
                                               AuthorizationServerTokenServices tokenServices,
                                               ClientDetailsService clientDetailsService) {
        return new ArrayList<>();
    }

    /**
     * 配置授权服务器的 token 接入点
     */
    default void configure(AuthorizationServerSecurityConfigurer security) throws Exception {}

    /**
     * 配置自定义ClientDetailsService
     */
    default void configure(ClientDetailsServiceConfigurer clients) throws Exception {}

    /**
     * 授权服务器端点配置
     */
    default void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {}
}